package com.springtest.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.annotation.JsonView;
import com.springtest.demo.model.ResultEntity;
import com.springtest.demo.model.Teacher;
import com.springtest.demo.serices.TeacherService;
import com.springtest.demo.views.TeacherView;

import javax.annotation.Resource;

@Controller
@RequestMapping("/teacher")
public class TeacherController {

	@Resource(name="teacherService")
	private TeacherService teacherService;

	@RequestMapping(value="save",method=RequestMethod.POST)
	public @ResponseBody ResultEntity save(@RequestBody Teacher teacher){
		
		return teacherService.save(teacher);
	}
	
	@RequestMapping(value="update",method=RequestMethod.POST)
	public @ResponseBody ResultEntity update(@RequestBody Teacher teacher){
		
		return teacherService.update(teacher);
	}

	@RequestMapping(value="delete/{id}",method=RequestMethod.GET)
	public @ResponseBody ResultEntity delete(@PathVariable int id){
		
		return teacherService.delete(id);
	}
	
	@RequestMapping(value="delete",method=RequestMethod.GET)
	public @ResponseBody ResultEntity delete(Teacher teacher){
		
		return teacherService.delete(teacher);
	}
	
	@JsonView(TeacherView.Teacher.class)
	@RequestMapping(value="findById/{id}",method=RequestMethod.GET)
	public @ResponseBody ResultEntity findById(@PathVariable int id){
		
		return teacherService.findById(id);
	}
	
	@JsonView(TeacherView.Teacher.class)
	@RequestMapping(value="findAll",method=RequestMethod.GET)
	public @ResponseBody ResultEntity findAll(){
		
		return teacherService.findAll();
	}	
	
}
